package com.server.questionbank.snframe.util.FileUtil.lifecycle;

import io.minio.DeleteBucketLifecycleArgs;
import io.minio.MinioClient;
import io.minio.SetBucketLifecycleArgs;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 生命周期管理器
 */
@RequiredArgsConstructor
@Component
public class LifecycleManager {
    private final MinioClient minioClient;
    
    /**
     * 设置存储桶生命周期规则
     */
    public void setBucketLifecycle(String bucket, LifecycleConfigurationBuilder builder) throws Exception {
        minioClient.setBucketLifecycle(
            SetBucketLifecycleArgs.builder()
                .bucket(bucket)
                .config(builder.build())
                .build()
        );
    }
    
    /**
     * 删除存储桶生命周期规则
     */
    public void deleteBucketLifecycle(String bucket) throws Exception {
        minioClient.deleteBucketLifecycle(
            DeleteBucketLifecycleArgs.builder()
                .bucket(bucket)
                .build()
        );
    }
} 